<?php

/**
 * This is the model class for table "equipo".
 *
 * The followings are the available columns in table 'equipo':
 * @property integer $id
 * @property string $numeroSerie
 * @property string $modelo
 * @property string $descripcion
 * @property integer $categoria_id
 * @property integer $marca_id
 */
class equipo extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'equipo';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('categoria_id, marca_id', 'required'),
			array('categoria_id, marca_id', 'numerical', 'integerOnly'=>true),
			array('numeroSerie, modelo', 'length', 'max'=>45),
			array('descripcion', 'length', 'max'=>100),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, numeroSerie, modelo, descripcion, categoria_id, marca_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'categoria' => array(self::BELONGS_TO, 'Categoria', 'categoria_id'),
			'marca' => array(self::BELONGS_TO, 'Marca', 'marca_id'),
			'reparacions' => array(self::HAS_MANY, 'Reparacion', 'equipo_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'Id',
			'numeroSerie' => 'Numero Serie',
			'modelo' => 'Modelo',
			'descripcion' => 'Nombre',
			'categoria_id' => 'Categoria',
			'marca_id' => 'Marca',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);

		$criteria->compare('numeroSerie',$this->numeroSerie,true);

		$criteria->compare('modelo',$this->modelo,true);

		$criteria->compare('descripcion',$this->descripcion,true);

		$criteria->compare('categoria_id',$this->categoria_id);

		$criteria->compare('marca_id',$this->marca_id);

		return new CActiveDataProvider('equipo', array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * @return equipo the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}